<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户管理</title>
	<%@ include file="/WEB-INF/include/include.jsp" %>
  </head>
  <body>
   
  </body>
</html>
	<ui:page>
		<ui:grid  id="roleGrid" var="roleGrid" width="210"  autoLoad="false"  showCheckbox="true"  showPaging="false" model="RoleModel" datasetName="SysUserRoleDataSetHandler" handlerName="SysUserRoleLoadHandler" handlerMethod="queryUserRoleAssign" title="未选角色">
			<x:attr name="region">west</x:attr>
			<x:attr name="border">false</x:attr>
			<x:attr name="layout">fit</x:attr>
			<x:columns>
				<ui:gridcolumn dataIndex="ROLE_ID" hidden="true" ></ui:gridcolumn>
				<ui:gridcolumn text="角色名称" dataIndex="ROLE_NAME" width="180">
				<x:attr name="flex">1</x:attr>
				</ui:gridcolumn>
			</x:columns>
		</ui:grid>
		<ui:toolbar id="toolbar" var="toolbar" width="30">
			<x:attr name="region">center</x:attr>
			<x:attr name="vertical" type="direct">true</x:attr>
			<x:items>
				<x:value>-></x:value>
				<ui:button text="分配" id="addBtn" iconCls="icon-add" handler="doAssign"></ui:button>
				<x:value>-</x:value>
				<ui:button text="取消" id="editBtn" iconCls="icon-edit"  handler="doAssignCancel"></ui:button>
				<x:value>-></x:value>
				<ui:button text="保存" id="saveBtn" iconCls="icon-save" handler="doSaveRole"></ui:button>
			</x:items>
		</ui:toolbar>
		<ui:grid  id="ed_roleGrid" var="ed_roleGrid"  width="210" autoLoad="false" showCheckbox="true" showPaging="false" model="RoleModel" datasetName="SysUserRoleDataSetHandler" handlerName="SysUserRoleLoadHandler" handlerMethod="queryUserRole" title="已选角色">
			<x:attr name="region">east</x:attr>
			<x:attr name="border">false</x:attr>
			<x:columns>
				<ui:gridcolumn dataIndex="ROLE_ID" hidden="true" ></ui:gridcolumn>
				<ui:gridcolumn text="角色名称" dataIndex="ROLE_NAME" width="180">
					<x:attr name="flex">1</x:attr>
				</ui:gridcolumn>
			</x:columns>
		</ui:grid>
		<ui:viewport layout="border">
			<x:items>
				<x:value type="direct">roleGrid</x:value>
				<x:value type="direct">toolbar</x:value>
				<x:value type="direct">ed_roleGrid</x:value>
			</x:items>
		</ui:viewport>
		
		<x:bottomScript>
			var record = window.parent.UserList.getSelectedOne();
			var ed_store = ed_roleGrid.getStore();
			var condition=new Condition("USER_ID",record.get('USER_ID'));
			ed_store.clearCondition();
			ed_store.addCondition(condition);
			ed_store.load();
 				
 				
 			var store = roleGrid.getStore();
			var condition2=new Condition("USER_ID",record.get('USER_ID'));
			store.clearCondition();
			store.addCondition(condition2);
			store.load();
			//分配按钮实现
			function doAssign(){
				var records=　 roleGrid.getSelectionModel().getSelection();
				var store = roleGrid.getStore();
				var ed_store = ed_roleGrid.getStore();
				var count = ed_store.getCount();
 				ed_store.insert(count,records);
 				store.remove(records);
			}
			//取消分配
			function doAssignCancel(){
				var records=　ed_roleGrid.getSelectionModel().getSelection()
				var ed_store = ed_roleGrid.getStore();
				var store = roleGrid.getStore();
				var count = store.getCount();
 				store.insert(count,records);
 				ed_store.remove(records);
			
			}
			//保存角色
			function doSaveRole(){
				var records=　ed_roleGrid.getStore().getRange(0,ed_roleGrid.getStore().getCount());
				var ds=new DataSet('SysUserRoleDataSetHandler','SysUserRoleData');
              	ds.setHandlerMethod("save");
              	ds.addCondition("USER_ID",record.get('USER_ID'));
				for(var i=0;i<records.length;i++){
					ds.newRecord();
					ds.setValue('ROLE_ID',records[i].get('ROLE_ID'));	
				}
				ds.execute();
				window.parent.Pearlsen.Page.currentWin.close();		
			}
		</x:bottomScript>
	</ui:page>

	
